<?php
/**
 * author Bibek Shrestha
 * bibekshrestha (at) gmail (dot) com
 * 
 * File has all the views theme override functions
 * 
 */


function phptemplate_views_view_list_sellingleads_search($view, $nodes, $type) {
  // dont handle the HTML here, 
  // instead use views-list-sellingleads.tpl.php
  $passArray = array ();  
  $profile = 0;
  foreach ($nodes as $key => $value) {
    $node = node_load($value->nid);    
    $passArray[$key]['uid'] = $node->uid;
    $passArray[$key]['nid'] = $node->nid;
    
    // get organization name
    $profile = userprofilehandler_loaduserprofile($node->uid);
    $passArray[$key]['author'] = $profile->organization;
    
    $passArray[$key]['created'] = $value->node_created_created;
    $passArray[$key]['img'] = theme('node_images_view', $node, TRUE, FALSE, '');
    $passArray[$key]['title'] = l($value->node_title, 'node/' . $value->nid);
    $passArray[$key]['body'] = $node->body;
    $passArray[$key]['price'] = $value->ec_product_price;
    $passArray[$key]['country'] = $value->node_data_field_product_location_field_product_location_country;
    $passArray[$key]['state'] = $value->node_data_field_product_location_field_product_location_state;
    $passArray[$key]['city'] = $value->node_data_field_product_location_field_product_location_city;
    
    $passArray[$key]['link_addtocart'] = module_invoke('product', 'link', 'node', $node);
  }
  $vars['nodes'] = & $passArray;
  $output = _phptemplate_callback('views-list-sellingleads', $vars);
  if ($output) {
    return $output;
  }
}

/**
 * FeaturedItems Listing in Frontpage
 * featureditems_listing_frontpage is set its own views-featureditems-listing-frontpage.tpl.php
 * through following code
 *
 * @param unknown_type $view
 * @param unknown_type $nodes
 * @param unknown_type $type
 * @return unknown
 */
function phptemplate_views_view_list_featureditems_listing_frontpage($view, $nodes, $type) {
    $fields = _views_get_fields();

  $taken = array();

  // Group our nodes
  $set = array();
  foreach ($nodes as $node) {
    $set[$node->node_title][] = $node;
  }

  // Set up the fields in nicely named chunks.
  foreach ($view->field as $id => $field) {
    $field_name = $field['field'];
    if (isset($taken[$field_name])) {
      $field_name = $field['queryname'];
    }
    $taken[$field_name] = true;
    $field_names[$id] = $field_name;
  }

  // Set up some variables that won't change.
  $base_vars = array(
    'view' => $view,
    'view_type' => $type,
  );

  $output = '';
  foreach ($set as $label => $nodes) {
    $items = array();
    foreach ($nodes as $i => $node) {
      $vars = $base_vars;
      $vars['node'] = $node;
      $vars['count'] = $i;
      $vars['stripe'] = $i % 2 ? 'even' : 'odd';
      foreach ($view->field as $id => $field) {
        $name = $field_names[$id];
        $vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
        if (isset($field['label'])) {
          $vars[$name . '_label'] = $field['label'];
        }
      }
      $items[] = _phptemplate_callback('views-list-featureditems-listing-frontpage', $vars);
    }

    if ($items) {
      $output .= theme('item_list', $items);
    }
  }
//  dpr($items);
  return $output;
  
 
}

function phptemplate_views_view_list_buyingleads($view, $nodes, $type) {
  // dont handle the HTML here, 
  // instead use views-list-mysellingleads.tpl.php
  $passArray = array ();
  foreach ($nodes as $key => $value) {
    $node = node_load($value->nid);
    
    $passArray[$key]['uid'] = $node->uid;
    $profile = userprofilehandler_loaduserprofile($node->uid);
    $passArray[$key]['author'] = $profile->organization;
    $passArray[$key]['nid'] = $node->nid;
    $passArray[$key]['created'] = $value->node_created_created;
    
    $passArray[$key]['title'] = l($value->node_title, 'node/' . $value->nid);
    $passArray[$key]['body'] = $node->body;
    $passArray[$key]['price'] = $value->ec_product_price;
    $passArray[$key]['country'] = $value->node_data_field_product_location_field_product_location_country;
    $passArray[$key]['state'] = $value->node_data_field_product_location_field_product_location_state;
    $passArray[$key]['city'] = $value->node_data_field_product_location_field_product_location_city;
  }
  $vars['nodes'] = & $passArray;
  $output = _phptemplate_callback('views-list-buyingleads', $vars);
  if ($output) {
    return $output;
  }
}

/**
 * Theming of Selling Leads View
 *
 * @param unknown_type $view
 * @param unknown_type $nodes
 * @param unknown_type $type
 * 
 * @todo 
 * both phptemplate_views_view_list_sellingleads and phptemplate_views_view_list_mysellingleads
 * can use same display code, see it later
 */
function phptemplate_views_view_list_sellingleads($view, $nodes, $type) {
  // dont handle the HTML here, 
  // instead use views-list-sellingleads.tpl.php
  $passArray = array ();  
  $profile = 0;
  foreach ($nodes as $key => $value) {
    $node = node_load($value->nid);    
    $passArray[$key]['uid'] = $node->uid;
    $passArray[$key]['nid'] = $node->nid;
    
    // get organization name
    $profile = userprofilehandler_loaduserprofile($node->uid);
    $passArray[$key]['author'] = $profile->organization;
    
    $passArray[$key]['created'] = $value->node_created_created;
    $passArray[$key]['img'] = theme('node_images_view', $node, TRUE, FALSE, '');
    $passArray[$key]['title'] = l($value->node_title, 'node/' . $value->nid);
    $passArray[$key]['body'] = $node->body;
    $passArray[$key]['price'] = $value->ec_product_price;
    $passArray[$key]['country'] = $value->node_data_field_product_location_field_product_location_country;
    $passArray[$key]['state'] = $value->node_data_field_product_location_field_product_location_state;
    $passArray[$key]['city'] = $value->node_data_field_product_location_field_product_location_city;
    
    $passArray[$key]['link_addtocart'] = module_invoke('product', 'link', 'node', $node);
  }
  $vars['nodes'] = & $passArray;
  $output = _phptemplate_callback('views-list-sellingleads', $vars);
  if ($output) {
    return $output;
  }
}

function phptemplate_views_view_list_mysellingleads($view, $nodes, $type) {

  // dont handle the HTML here, 
  // instead use views-list-mysellingleads.tpl.php
  $passArray = array ();  
  foreach ($nodes as $key => $value) {
    $node = node_load($value->nid);    
    $passArray[$key]['created'] = $value->node_created_created;
    $passArray[$key]['author'] = $value->users_name;
    $passArray[$key]['img'] = theme('node_images_view', $node, TRUE, FALSE, '');
    $passArray[$key]['title'] = l($value->node_title, 'node/' . $value->nid);
    $passArray[$key]['body'] = $node->body;
    $passArray[$key]['price'] = $value->ec_product_price;
    $passArray[$key]['nid'] = $value->nid;
    $passArray[$key]['country'] = $value->node_data_field_product_location_field_product_location_country;
    $passArray[$key]['state'] = $value->node_data_field_product_location_field_product_location_state;
    $passArray[$key]['city'] = $value->node_data_field_product_location_field_product_location_city;
    $passArray[$key]['display'] = $value->ec_config_products_display;
    $passArray[$key]['expiry'] = $value->ec_product_expiry_options_active;

  }
  $vars['nodes'] = & $passArray;
  $output = _phptemplate_callback('views-list-mysellingleads', $vars);
  if ($output) {
    return $output;
  }

}

function phptemplate_views_view_list_mybuyingleads($view, $nodes, $type) {
  print "phptemplate_views_view_list_mybuyingleads";
  $output = '
    <style>
  .itemTitle {
  background:#F2F2F2 none repeat scroll 0%;
  border-color:#bcbcbc;
  border-style:solid solid !important;
  border-width:1px 1px !important;
  font-family:tahoma;
  font-size:0.9em;
  font-weight:bold;
  height:26px;
  padding-bottom:0pt !important;
  }
    
  .itemBox {
       border-bottom:1px dotted #A9B4C3;
       margin-bottom:8px;
       padding-bottom:8px;
     
  }
  
  
  .itemBox .box3 {
  float:left;
  overflow:hidden;
  width:45%;
  padding-left:10px;
  }
  
  .itemBox .box5 {
  float:left;
  text-align:center;
  width:100px;
  padding-left:10px;
  }
  
  .itemBox .box6 {
  float:left;
  margin-left:3px !important;
  width:100px;
  padding-left:10px;
  }
  </style>
  <div class="itemBox itemTitle"  >
  
  
  <div class="box3">Description</div>
  
  <div class="box5">
  <div class="selectRegion">
  Region
  </div>
  </div>
  <div class="box6">Contact</div>
  <div style="clear: both;"></div>
  </div>
  
     <div class="itemBox">
          
         <div class="box3">
        <h2>peanut butter</h2>
      <span class="date">Oct 25, 2007</span>
            <div class="widthfixed description">
              Type: 
                 1) Peanut kernels long shape (size: 20/24, 24/28, 28/32, 34/38, 38/42, 45/55) 
  
           </div>
                  
          <br>
              <div class="companyname">
            peanut co.
           </div>         
                    
      </div>
        <div class="box5">
    
        jumla   
       </div>   
     
       <div class="box6">
        <a title="TradeManager" class="atm16grey" style="display: block; width: 70px; line-height: 22px;" id="talkId1" href="jsdsj">Offline</a>
          </div>
        <div style="clear: both;"></div>
        
    </div>
  ';
  return $output;
}
?>
